package com.sceneworker.monitorpopup;

import java.awt.event.ActionEvent;

import javax.swing.tree.TreePath;

import com.jme.light.Light;
import com.jme.scene.Spatial;
import com.jme.scene.state.LightState;

public class LightMenu extends BaseMenu {

	private static final String DETACH = "Detach";
	private		Light				mcl_light;
	private		LightState			mcl_ls;
	private		Spatial				mcl_spatial;
	
	public LightMenu(TreePath cl_selectedPath, SceneWorkerPopUp cl_menu) {
		super(cl_menu);
		
		mcl_light = (Light)cl_selectedPath.getLastPathComponent();
		mcl_ls = (LightState)cl_selectedPath.getParentPath().getLastPathComponent();
		
		if(cl_selectedPath.getParentPath().getParentPath().getLastPathComponent() instanceof Spatial) {
			mcl_spatial = (Spatial)cl_selectedPath.getParentPath().getParentPath().getLastPathComponent();
		}
		
		buildMenu();
	}

	@Override
	public void actionPerformed(ActionEvent cl_e) {
		if(cl_e.getActionCommand().equals(DETACH)) {
			mcl_ls.detach(mcl_light);
			
			if(mcl_spatial != null) {
				mcl_spatial.updateRenderState();
			}
		}
	}

	@Override
	protected void buildMenu() {
		mcl_menu.addSeparator();
		mcl_menu.add(buildAMenuItem(DETACH));
	}

}
